package xin.lhuo.we.server.dao;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Component;
import xin.lhuo.we.server.entity.NodeCategory;

import java.util.List;

/**
 * @author Lhuo
 * @date 2019/6/29 17:30
 */
@Mapper
@Component
public interface NodeCategoryMapper {

    @Insert("insert into we_node_category (user_id,name) values(#{userId},#{name})")
    void saveNodeCategory(NodeCategory nodeCategory);

    @Select("select * from we_node_category where user_id = #{userId}")
    @Results(id = "nodeCategory",
            value = {
                    @Result(column = "id", property = "id", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "user_id", property = "userId", javaType = Integer.class, jdbcType = JdbcType.INTEGER),
                    @Result(column = "name", property = "name", javaType = String.class, jdbcType = JdbcType.VARCHAR),
                    @Result(column = "desc", property = "desc", javaType = String.class, jdbcType = JdbcType.VARCHAR),


            })
    List<NodeCategory> getNodeCategory(Integer userId);

    @Delete("delete from we_node_category where id = #{id}")
    void deleteNodeCategory();

    @Select("select count(id) from we_node_category where name = #{name} and user_id = #{userId}")
    int checkName(Integer userId,String name);
}
